<?php

namespace App\Models;

use App\Models\Device;
use App\Models\DeviceGroup;
use App\Models\Sentence;
use Illuminate\Database\Eloquent\Model;

class DeviceGroupSentence extends Model
{
    protected $fillable = [
        'type',
        'wechat_name',
        'content1',
        'content2',
        'device_group_id',
        'priority',
    ];

    public function deviceGroup()
    {
        return $this->belongsTo(DeviceGroup::class);
    }

    public function deviceGroupAdd()
    {
        return $this->belongsTo(DeviceGroupAdd::class);
    }

//    public function finishedDevices()
//    {
//        // 只返回当天完成任务的设备
//        return $this->belongsToMany(Device::class,'sentence_device', 'device_group_sentence_id', 'device_id')->where(\DB::raw("DATE_FORMAT(finished_time,'%Y-%m-%d')"), '=', \Carbon\Carbon::now()->toDateString());
//    }
//    public function deviceIsFinished($device_id)
//    {
//        return $this->finishedDevices->contains($device_id);
//    }

//    public function addFinishedDevices($device_ids)
//    {
//        if(!is_array($device_ids)) {
//            $device_ids = compact('device_ids');
//        }
//        $this->finishedDevices()->attach($device_ids);
//    }
}
